import org.apache.http.client.CookieStore;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.cookie.BasicClientCookie;

import java.io.IOException;

public class Test {
    public static void main(String[] args) throws IOException {
        // 替换成你的目标URL
        String loginUrl = "http://jwgl.cuit.edu.cn/eams/home.action";

        // 替换成你的Cookie信息
        String cookieName = "GSESSIONID";
        String cookieValue = "E8642BEB0F786CBB4258A285D5C0850D";

        // 创建HttpClient对象
        CloseableHttpClient httpClient = HttpClients.createDefault();

        // 创建一个HttpPost请求
        HttpPost postRequest = new HttpPost(loginUrl);

        // 创建一个CookieStore并添加Cookie
        CookieStore cookieStore = new BasicCookieStore();
        BasicClientCookie cookie = new BasicClientCookie(cookieName, cookieValue);
        cookie.setDomain("example.com");  // 替换为你的域名
        cookie.setPath("/");
        cookieStore.addCookie(cookie);

        // 将CookieStore设置到HttpClient中
        RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).build();
        postRequest.setConfig(requestConfig);

        // 发送请求
        try (CloseableHttpResponse response = httpClient.execute(postRequest)) {
            System.out.println("Response Status: " + response.getStatusLine());
            response.getEntity().writeTo(System.out);  // 输出响应内容
        }

        // 关闭HttpClient
        httpClient.close();
    }
}